<?php

class BolaoSubcategoryPeer extends BaseBolaoSubcategoryPeer
{
  public static function fromCategoryCriteria($category)
  {
    if ($category instanceof BolaoCategory)
      $category_id = $category->getId();
    else
      $category_id = $category;

    $criteria = new Criteria();
    $criteria->add(BolaoSubcategoryPeer::CATEGORY_ID, $category_id, Criteria::EQUAL);

    return $criteria;
  }

  static function retrieveByNameSlug($name_slug, $category)
  {
    // Mount name search string
    $name = str_replace('-', '_', $name_slug);

    $criteria = new Criteria();
    $cron = $criteria->getNewCriterion(BolaoSubcategoryPeer::NAME, $name, Criteria::LIKE);
    $cron->addAnd($criteria->getNewCriterion(BolaoSubcategoryPeer::CATEGORY_ID, $category->getId()));
    $criteria->add($cron);
    $criteria->setIgnoreCase(true);

    $result = BolaoSubcategoryPeer::doSelect($criteria);
    
    // If more than one result, return first result
    if (count($result) >= 1)
      return $result[0] ;
    else
      return NULL;
  }
}
